// miniprogram/pages/index/index_more/index_more.js
const { index_sort,fjRecommend } = require('../../../config/sorts');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeTabIndex : 0,
    activeItem1 : false,
    activeItem2 : false,
    activeItem3 : false,
    activeEF: false,
    activeEF1 : false,
    activeEF2 : false,
    activeEF3 : false,
    index_sort: [],
    title1: '全部类型',
    title2: '全部风格',
    title3: '全部状态',
    title : '',
    fjRecommend
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  doListChange(e) {
    let index = e.detail.current;
    this.setData({
      activeTabIndex: index
    })
  },
  switchTab(e){
    // console.log(e);
    let index = e.currentTarget.dataset.index;
    if(index == this.data.activeTabIndex){
      return ;
    }
    this.setData({
      activeTabIndex: index,
    })
  },
  expandFold (e) {
    let siftType = e.currentTarget.dataset.sifttype;
    let index_sort1 = index_sort.filter((is) => is.type == siftType);
    this.setData({
      index_sort : index_sort1
    })
  },
  expandFold1 (e) {
    this.expandFold(e);
    let activeEF = e.currentTarget.dataset.activeef1;
    if (activeEF == true) {
      this.setData({
        activeEF1: !activeEF
      })
      return
    }
    this.setData({
      activeEF1: !activeEF,
      activeEF2: activeEF,
      activeEF3: activeEF,
      activeEF : !activeEF
    })
  },
  expandFold2 (e) {
    this.expandFold(e);
    let activeEF = e.currentTarget.dataset.activeef2;
    if (activeEF == true) {
      this.setData({
        activeEF2: !activeEF
      })
      return
    }
    this.setData({
      activeEF1: activeEF,
      activeEF2: !activeEF,
      activeEF3: activeEF,
      activeEF : !activeEF
    })
  },
  expandFold3 (e) {
    this.expandFold(e);
    let activeEF = e.currentTarget.dataset.activeef3;
    if (activeEF == true) {
      this.setData({
        activeEF3: !activeEF
      })
      return
    }
    this.setData({
      activeEF1: activeEF,
      activeEF2: activeEF,
      activeEF3: !activeEF,
      activeEF : !activeEF
    })
  },
  itemSelected(e) {
    let title1,
        title2,
        title3;
    let { activeitem1,activeitem2,activeitem3 } = e.currentTarget.dataset;
    let type = e.currentTarget.dataset.type;
    let title = e.currentTarget.dataset.title;
    if (type == 'mtype') {
      if (!activeitem1) {
        this.setData({
          activeItem1 : !activeitem1
        })
      }
     this.setData({
      title1 : title
     })
    }
    if (type == 'mstyle') {
      if (!activeitem2) {
        this.setData({
          activeItem2 : !activeitem2
        })
      }
     this.setData({
      title2 : title
     })
    }
    if (type == 'mstate') {
      if (!activeitem3) {
        this.setData({
          activeItem3 : !activeitem3
        })
      }
      this.setData({
        title3 : title
      })
    }
    
    let fjRecommend1 = fjRecommend.filter((fj) => {
      let mtype = fj.mtype, 
          mstyle = fj.mstyle, 
          mstate = fj.mstate;
      if (this.data.title1.slice(0,2) == '全部') {
        mtype = '全部';
        this.data.title1 = '全部';
      }
      if (this.data.title2.slice(0,2) == '全部') {
        mstyle = '全部';
        this.data.title2 = '全部';
      }
      if (this.data.title3.slice(0,2) == '全部') {
        mstate = '全部';
        this.data.title3 = '全部';
      }
      console.log(mstyle, this.data.title2, mstyle == this.data.title2,'========');
      if(mtype == this.data.title1 && mstyle == this.data.title2 && mstate == this.data.title3) {
        return fj;
      }
    })
    this.setData({
      fjRecommend : fjRecommend1
    })
   
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})